package com.example.fushuang.balabala.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.example.fushuang.balabala.R;
import com.example.fushuang.balabala.adapter.AvRecycleAdapter;
import com.example.fushuang.balabala.model.VideoDetail;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class AvPlayIntroduceFragment extends BaseFragment {


    private List<VideoDetail.DataBean.RelatesBean> mRelates; //防止无数据时候空指针
    private AvRecycleAdapter mAdapter;

    public AvPlayIntroduceFragment() {
        // Required empty public constructor

    }
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onReceiveDetail(VideoDetail detail){
//        mRelates = detail.getData().getRelates();
        mRelates.clear();
        mRelates.addAll(detail.getData().getRelates());
        mAdapter.notifyDataSetChanged();
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EventBus.getDefault().register(this);

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Override
    public String getFragmentTitle() {
        return "简介";
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment

        mRelates=new ArrayList<>(); //防止无数据时候空指针

        View view = inflater.inflate(R.layout.fragment_av_play_introdece, container, false);
        RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.av_introduce_recycleView);
        LinearLayoutManager lm = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
        recyclerView.setLayoutManager(lm);
        mAdapter = new AvRecycleAdapter(getContext(), mRelates);
        recyclerView.setAdapter(mAdapter);
        //设置这个让recycleView自己滚动,不让外面的NestedScrollView接收滚动时间
        recyclerView.setNestedScrollingEnabled(false);

        return view;

    }

}
